const dns = require('dns');

//解析域名-根据域名找ip
dns.lookup('nodejs.cn', (err, address, family) => {
	console.log(`地址: ${address}  地址族:${family}`);//地址: 112.124.39.54  地址族:4
});
//反向域名解析-根据ip找域名
dns.reverse('112.124.39.54',(err, hostnames)=>{
    //if(err) throw err;
    console.log(hostnames);
    //结果为[ 'nodejs.cn' ]
});

//dns.lookupService('182.61.200.6', 80, (err, hostname, service) => {
dns.lookupService('127.0.0.1', 22, (err, hostname, service) => {
	console.log(hostname, service);//DESKTOP-LQO4D8A ssh
});


dns.resolve('www.baidu.com', (err, records) => {
	console.log(records);//[ '182.61.200.6', '182.61.200.7' ]
});

